import Taro from '@tarojs/taro';
import {Image, View} from '@tarojs/components';
import {connect} from "@tarojs/redux";
import {request, unite} from '../../../utils/index';
import './selectCourse.scss';
import None from "../../../asset/images/none.png";


class MyCoupon extends Taro.Component {
    config = {
        navigationBarTitleText: '我的课程',
        backgroundColor: '#F6F7F7',
        navigationStyle: 'custom'
    };

    state = {
        dataList: [],
    };

    componentDidShow() {
        this.init();
    }

    init = () => {
        const params = {
            url: '/wx/coach/myClassInfo',
            data:{}
        };
        request(params).then(res => {
            Taro.stopPullDownRefresh(); //停止当前页面下拉刷新
            if (res) {
                if(res.code == 200) {
                    if (res && res.data) {
                        this.setState({
                            dataList: res.data,
                        })
                    }
                }
            }
        })
    };

    render() {
        const {dataList} = this.state;
        let option = this.$router.params;
        console.log(option.roomId);
        return (
            <View className="myPage">
                <View className="head-tops">
                    <View className="head-img-return" onClick={() => {Taro.navigateBack({delta: 1})}}></View>
                    <View className="head-text">我的课程</View>
                </View>
                {dataList.length != 0 ? (
                    <View className="course-wrap">
                        {/*{dataList.map((item, index) => (*/}
                        {/*    <View className="course-list flex-top" key={index} onClick={() => {Taro.redirectTo({url: '../arranging-coursey-next/arrangingCourseyNext?id=' + item.classRefId+'&roomId='+option.roomId})}}>*/}
                        {/*        <Image className="course-img" mode="widthFix" src={item.avatar}/>*/}
                        {/*        <View className="course-content flex-lr">*/}
                        {/*            <View>*/}
                        {/*                <View className="course-name text-overflow">{item.className}</View>*/}
                        {/*                <View className="flex-l">*/}
                        {/*                    <View className="course-g flex-center">{item.classScaleName}</View>*/}
                        {/*                    <View>¥{item.price}/节</View>*/}
                        {/*                </View>*/}
                        {/*                <View className="flex-l">*/}
                        {/*                    {item.labelNames.map((value, is) => (*/}
                        {/*                        <View className="course-gg flex-center" key={is}>{value}</View>*/}
                        {/*                    ))}*/}
                        {/*                </View>*/}
                        {/*            </View>*/}
                        {/*            /!*<View className="course-btn course-btn-next flex-center" >{item.dispatchStatus ? '查看排课' : '去排课'}</View>*!/*/}
                        {/*        </View>*/}
                        {/*    </View>*/}
                        {/*))}*/}
                        {dataList.map((val, i) => {
                            if (val.studentNum == '') return;
                            return (
                                <View key={i}>
                                    <View className="course-names">{val.scaleName}</View>
                                    {val.weiXinMyClassInfoResp.map((item, index) => {
                                        return (
                                            <View className="course-list flex-lr" key={index} onClick={() => {Taro.redirectTo({url: '../arranging-coursey-next/arrangingCourseyNext?id=' + item.classRefId + '&roomId=' + option.roomId})}}>
                                                <Image className="course-img" mode="widthFix" src={item.avatar}/>
                                                <View className="course-content flex-lr">
                                                    <View>
                                                        <View className="course-name text-overflow">{item.className}</View>
                                                        <View className="flex-l">
                                                            <View className="course-g flex-center">{item.classScaleName}</View>
                                                            <View>¥{item.price}/节</View>
                                                        </View>
                                                        {/*<View className="flex-l">*/}
                                                        {/*    {item.labelNames.map((value, is) => (*/}
                                                        {/*        <View className="course-gg flex-center" key={is}>{value}</View>*/}
                                                        {/*    ))}*/}
                                                        {/*</View>*/}
                                                    </View>
                                                    {val.studentNum == '' ? (
                                                        <View className="course-btn course-btn-next course-btn-next-sh flex-center">审核中</View>
                                                    ) : (
                                                        <View className="course-btn course-btn-next flex-center" onClick={(e) => {e.stopPropagation();Taro.navigateTo({url: '../arranging-coursey/arrangingCoursey?id=' + item.classRefId + '&classId=' + item.classId})}}>{item.dispatchStatus ? '查看排课' : '排课'}</View>
                                                    )}
                                                </View>
                                            </View>
                                        )
                                    })}
                                </View>
                            )
                        })}
                        <View className="course-add-btn">
                            <View className="btn flex-center" onClick={() => {Taro.navigateTo({url: '../add-coursey/addCourse'})}}>添加课程</View>
                        </View>
                    </View>
                ) : (
                    <View className="none-wrap-page">
                        <Image className="none-img" src={None}/>
                        <View>暂无课程…</View>
                        <View className="none-max-btn" onClick={() => {Taro.navigateTo({url: '../add-coursey/addCourse'})}}>添加课程</View>
                    </View>
                )}
            </View>
        )
    }
}

const mapStateToProps = state => {
    let {} = state;
    return {
    }
};

const mapDispatchToProps = {
};

export default connect(mapStateToProps, mapDispatchToProps)(MyCoupon);



